package ctrLag;
import modelLag.*;

/**
 * Controller for order
 * 
 * @author (Christian, Umut, Christoffer, Patrick, Simon) 
 * @project (Semesterprojekt)
 * @version (2014.12.09)
 */

public class OrderCtr
{
   private OrderCon oCon;
   private CustomerCtr cCtr;
   private ProductCtr pCtr;
   
   /**
    * Constructor for objects of class OrderCtr
    */
   public OrderCtr(){
       oCon = OrderCon.getInstance();
       cCtr = new CustomerCtr();
       pCtr = new ProductCtr();
   }
   
   /**
    * Return an object of the type Customer, found using that customers phone.
    * 
    * @param phone is the user input for the phone.
    */
   public Customer findCustomer(String phone){
        return cCtr.findCustomer(phone);
   }
   
   /**
    * Return an object of the type Order.
    * 
    * @param customer is the user input for the customer.
    * @param employee is the user input for the employee.
    */
   public Order createOrder(Customer customer, Employee employee){
       Order o = new Order(customer, employee);
       return o;
   }
   
   /**
    * Return an object of the type Product.
    * 
    * @param ID is the user input for the ID of a product.
    */
   public Product findProduct(int ID){
       return pCtr.findProduct(ID);
   }
   
   /**
    * Return the newly calculated total.
    * 
    * @param o is the user input for an Order.
    * @param p is the user input for a Product.
    * @param a is the user input for the amount of products.
    */
   public double addProduct(Order o, Product p, int a){
       PartOrder po = new PartOrder(a, p);
       p.decrementStock(a);
       p.incrementSold(a);
       o.addPartOrder(po);
       o.addToTotal(p.getPrice() * a);
       return o.getTotal();
   }
   
   /**
    * Return an object of the type Order.
    * 
    * @param o is the user input for an Order.
    */
   public Order endOrder(Order o){
       o.setStatus(1);
       oCon.addOrder(o);
       return o;
   }
}